package com.example.verticles;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;

public class MainVerticle extends AbstractVerticle {

    @Override
    public void start(Promise<Void> promise) throws Exception {
        Promise<String> dbVerticleDeployment = Promise.promise();

//        vertx.deployVerticle(new WikiDatabaseVerticle(),dbVerticleDeployment);
        vertx.deployVerticle(WikiDatabaseVerticle.class.getName(),new DeploymentOptions().setInstances(2),dbVerticleDeployment);

        dbVerticleDeployment.future()
                .compose(id->{
                    Promise<String> httpVerticleDeployment = Promise.promise();

                    vertx.deployVerticle(HttpServerVerticle.class.getName(),
                            new DeploymentOptions().setInstances(2),
                            httpVerticleDeployment);

                    return httpVerticleDeployment.future();
                }).onComplete(ar->{
                    if (ar.failed()){
                        promise.fail(ar.cause());
                    }else {
                        promise.complete();
                    }
        });
    }
}
